import sys
import time

def calculate_days_to_lose_weight(reduce):
    return round(reduce / 0.15)

def calculate_heart_rate(age):
    return round((220 - age) * 0.65)

def calculate_calories(weight, speed, leave):
    calories_per_minute_per_kg = 0.1 * (speed / 10) + 3
    return weight * calories_per_minute_per_kg * (leave / 60)

def main():
    age = int(input("请输入您的年龄："))
    reduce = float(input("请输入您计划减肥的量（KG）："))
    day = calculate_days_to_lose_weight(reduce)
    heart = calculate_heart_rate(age)
    print('减肥{}公斤，需要大约{}天的最佳运动'.format(reduce, day))
    print('年龄{}岁，适合跑步的心率为{}次/分钟'.format(age, heart))
    weight = float(input("请输入您的体重（KG）："))
    speed = float(input("请输入您的跑步速度（公里/小时）："))
    while speed <= 0:
        print('跑步速度不能为0，请重新输入！')
        speed = float(input("请输入您的跑步速度（公里/小时）："))
    times = int(input("请输入您的跑步时间（分钟）："))
    leave = 0
    while leave < times * 60:
        min, sec = divmod(times * 60 - leave, 60)
        leave_time = f'{int(min)}分{int(sec)}秒'
        dista = leave / 3600 * speed
        calor = calculate_calories(weight, speed, leave)
        sys.stdout.write('\r剩余时间：{} 跑步距离:{:.2f} 公里 消耗热量：{:.2f} 千卡'.format(leave_time, dista, calor))
        sys.stdout.flush()
        time.sleep(1)
        leave += 1
    input('\n跑步结束，请按任意键退出！')

if __name__ == '__main__':
    main()
